package bjtu.tjj.simpledy.controller;

import bjtu.tjj.simpledy.common.CommonResult;
import bjtu.tjj.simpledy.dto.PublishVideoRespDTO;
import bjtu.tjj.simpledy.dto.VideoDTO;
import bjtu.tjj.simpledy.service.VideoService;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("video")
public class VideoController {
    private final VideoService videoService;

    @PostMapping
    public CommonResult<PublishVideoRespDTO> publish(
            @RequestPart("video") MultipartFile video,
            @RequestPart(name = "label", required = false) String label
    ) {
        return CommonResult.success(videoService.publish(video, label));
    }

    @DeleteMapping("{videoId}")
    public CommonResult<Void> delete(@PathVariable Long videoId) {
        videoService.delete(videoId);
        return CommonResult.success();
    }

    @GetMapping("liked")
    public CommonResult<List<VideoDTO>> getLiked(
            @RequestParam(defaultValue = "1") @Min(value = 1, message = "页号最小为1") Integer page,
            @RequestParam(defaultValue = "18") @Min(value = 1, message = "个数最小为1") Integer size
    ) {
        return CommonResult.success(videoService.getLiked(page, size));
    }

    @GetMapping("published")
    public CommonResult<List<VideoDTO>> getPublished(
            @RequestParam(defaultValue = "1") @Min(value = 1, message = "页号最小为1") Integer page,
            @RequestParam(defaultValue = "18") @Min(value = 1, message = "个数最小为1") Integer size
    ) {
        return CommonResult.success(videoService.getPublished(page, size));
    }
}
